package com.dhecp.project.base.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSON;
import com.dhecp.common.core.domain.AjaxResult;
import com.dhecp.common.utils.StringUtils;
import com.dhecp.core.constant.DataFiltering;
import com.dhecp.core.utils.PageUtils;
import com.dhecp.project.base.domain.BaseStockType;
import com.dhecp.project.base.mapper.BaseStockTypeMapper;
import com.dhecp.project.base.service.BaseStockTypeService;
import com.dhecp.project.system.service.SysDictionaryForFieldService;

@Service
public class BaseStockTypeServiceImpl implements BaseStockTypeService {
	
	@Autowired
	private BaseStockTypeMapper baseStockTypeMapper;
	
	@Autowired
	private SysDictionaryForFieldService dictionaryForFieldService;

	/**
	 * 查询
	 * @param params
	 * @return List-BaseStockType
	 * @throws Exception
	 */
	@Override
	public List<BaseStockType> queryList(Map<String, Object> params) throws Exception {
		params.put(DataFiltering.DATA_WHERE, dictionaryForFieldService.getWhereStr(params));		//常规查询条件SQL语句
//        params.put(DataFiltering.DATA_SCODE, dictionaryForFieldService.getDataScode(params));		//数据权限查询条件SQL语句
        PageUtils.startPage();
		return baseStockTypeMapper.findList(params);
	}

	/**
	 * 修改是否先进先出
	 * @param baseStockTypeItems
	 * @return List-BaseStockType
	 */
	@Override
	public AjaxResult updateBXjXc(String baseStockTypeItems) {
		if (StringUtils.isEmpty(baseStockTypeItems)) {
			return AjaxResult.error("数据提交失败，必填参数有误！");
		}
		List<BaseStockType> baseStockTypeList = JSON.parseArray(baseStockTypeItems, BaseStockType.class);
		if (baseStockTypeList == null || baseStockTypeList.size() == 0) {
			return AjaxResult.error("数据包格式有误，请检查！");
		}
		for (BaseStockType baseStockType : baseStockTypeList) {
			baseStockTypeMapper.updateBXjXc(baseStockType);
		}
		return AjaxResult.success("操作成功！");
	}

}
